//
//  DishAlbumNavView.m
//  XRmenu
//
//  Created by loufq on 11-3-21.
//  Copyright 2011 E0571. All rights reserved.
//

#import "DishAlbumNavView.h"

@implementation DishAlbumNavView
@synthesize mPC;
@synthesize delegate;

-(void)dealloc
{
	self.delegate = nil;
	self.mPC = nil;
	[super dealloc];
}

-(id) initWithConfig:(NSDictionary *)cfg
{
	if ((self = [super initWithConfig:cfg])) {
		self.backgroundColor = [UIColor clearColor];
		CGRect f =CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
		UIPageControl* pageControl =[[UIPageControl alloc] initWithFrame:f];
		[pageControl setBackgroundColor:[UIColor blackColor]];
		[pageControl addTarget:self action:@selector(pageIndexChange:) forControlEvents:UIControlEventValueChanged];
		pageControl.backgroundColor = [UIColor clearColor];
		//pageControl.numberOfPages=[[APPSESSION dishdata] count];
		self.mPC = pageControl;
		[self addSubview:pageControl];
		[pageControl release];
	}
	return self;
}

-(void)pageIndexChange:(UIPageControl*)aPageControl
{
	DebugLog(@"changed:%D",aPageControl.currentPage);
	if (self.delegate) {
		[self.delegate dishAlbumNavView:self perIndex:perIndex changToIndex:aPageControl.currentPage];
	}
	perIndex = aPageControl.currentPage;
	
}

-(BOOL) setPageCount:(NSInteger)aIndex
{
	self.mPC.numberOfPages = aIndex;
	return YES;
}

-(BOOL) setcurrentPageIndex:(NSInteger)aIndex
{
	self.mPC.currentPage = aIndex > (self.mPC.numberOfPages-1 )?self.mPC.numberOfPages-1:aIndex;
	return YES;
}

@end
